<template>
  <div class="goodsFooter">
    <template v-if="item.status === '2'">
      <div class="button orange" @click.stop="UpdateOrder">确认收货</div>
      <div
        class="button"
        @click.stop="to_router('myOrder-afterSales', item)"
      >
        售后
      </div>
    </template>
    <div
      class="button orange"
      @click.stop="PayGoodsOrder"
      v-else-if="item.status == '0'"
    >
      待支付
    </div>
  </div>
</template>
<script>
import { Toast, Dialog } from "vant";
import { updateOrder } from "@/api/myOrderManagement";
export default {
  components: {
    [Toast.name]: Toast,
    [Dialog.Component.name]: Dialog.Component,
  },
  props: {
    item: {
      type: Object,
      delete: [],
    },
  },
  methods: {
    PayGoodsOrder() {
      this.$emit("Pay");
    },
    to_router(name, query) {
      this.$emit("open");
      this.$router.push({
        name: name,
        query,
      });
    },
    UpdateOrder() {
      Dialog.confirm({
        title: "确认收货",
        message: "为了保障您的售后权益，收到商品请先检查无误再点击确认收货",
      })
        .then(() => {
          const data = {
            orderNo: this.item.orderNo,
            statusId: "5",
            No_RSA: true,
          };
          const toast = Toast.loading({
            duration: 0,
            forbidClick: true,
            message: "提交中...",
          });
          updateOrder(data).then((res) => {
            if (res.data.resultStatus) {
              Toast.success(res.data.errorMessage);
              this.$emit("load");
            } else {
              Toast.fail(res.data.errorMessage);
            }
            const timer = setInterval(() => {
              clearInterval(timer);
              Toast.clear();
            }, 1000);
          });
        })
        .catch(() => {
          // on cancel
        });
    },
  },
};
</script>
<style lang="less" scoped>
.goodsFooter{
  width: 100%;
  display: flex;
  justify-content: flex-end;
}
</style>